/**
 * Created by soil on 2018/2/28.
 */
var $table = $('#table'),$remove = $('#remove'),$show = $('#show'),$full = $('#full');
var data = [];
var pointList = [];
var marker = null;
var circle = null;
var markerArr = [];
var point;
var repeat = [];
var length;
var $table = $('#table')
var $button = $('#button')
var localObj = {
    center:{
        lng:0,
        lat:0
    },
    list:{
    },
    range:1000,
    search:"",
    placename:"",
}
var map = new BMapGL.Map("allmap",{
        // enableMapClick: false,
        // mapType: BMAP_SATELLITE_MAP // 默认为卫星图
});        // 创建Map实例
var ply;  //行政区划
map.centerAndZoom(new BMapGL.Point(121.480279,31.236272),13);
map.enableScrollWheelZoom();
map.addControl(new BMapGL.CityListControl({anchor: BMAP_ANCHOR_TOP_RIGHT}));
map.addControl(new BMapGL.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT}));
map.addControl(new BMapGL.MapTypeControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT,offset: new BMapGL.Size(10, 25)}));
map.addControl(new BMapGL.NavigationControl({
    anchor:BMAP_ANCHOR_TOP_LEFT,
    type: BMAP_NAVIGATION_CONTROL_LARGE,
    enableGeolocation: true
}))
var ac = new BMapGL.Autocomplete(    //建立一个自动完成的对象
    {"input" : "suggestId"
        ,"location" : map
    });
    
ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
    var str = "";
    var _value = e.fromitem.value;


    var value = "";
    if (e.fromitem.index > -1) {
        value = _value.province + _value.city + _value.district + _value.street + _value.business;
    }
    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
    value = "";
    if (e.toitem.index > -1) {
        _value = e.toitem.value;
        value = _value.province + _value.city + _value.district + _value.street + _value.business;
    }
    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
    document.getElementById('searchResultPanel').innerHTML = str;
});
var myValue;
ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
    var _value = e.item.value;
	     console.log($('#suggestId').val());
    localObj.placename= $('#suggestId').val(); 
    myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
    document.getElementById('searchResultPanel').innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
    setPlace()
});
//本地储存
function setPlace(){
    map.clearOverlays();    //清除地图上所有覆盖物
    function myFun(){
        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
        localObj.center = pp
        console.log(localObj)
        
        map.centerAndZoom(pp, 16);//设置中心点坐标和地图级别
        marker = new BMapGL.Marker(pp);
        marker.enableDragging();//点可拖拽
        map.addOverlay(marker);    //添加标注      
    }
    $(function() {
        $button.click(function () {
            //本地存储localstorage
            var ttt= $table.bootstrapTable('getSelections')
            localObj.list = ttt
              var ddd=JSON.stringify(localObj);
              localStorage.setItem('localData',ddd);
              console.log(localObj.list)
        //   alert('getSelections: ' + JSON.stringify($table.bootstrapTable('getSelections')))
        })
      })
    let local = new BMapGL.LocalSearch(map, { //智能搜索
        onSearchComplete: myFun
    });
    local.search(myValue)
};
function fullControl(){
    this.defaultAnchor = BMAP_ANCHOR_BOTTOM_LEFT;
    this.defaultOffset = new BMapGL.Size(20, 20);
}
fullControl.prototype = new BMapGL.Control();
fullControl.prototype.initialize = function(map){
    // 创建一个DOM元素
    var btn = document.createElement("button");
    btn.setAttribute('class','btn btn-default')
    btn.appendChild(document.createTextNode("全屏"));
    btn.onclick = function(e){
        $('#allmap').toggleClass('full')
    }
    map.getContainer().appendChild(btn);
    return btn;  
}
// 创建控件
var myZoomCtrl = new fullControl();
// 添加到地图当中
map.addControl(myZoomCtrl);
// map.addEventListener("click",function(e){
// //        alert(e.point.lng + "," + e.point.lat);
// //        console.log(e.point.lng + "," + e.point.lat)
//     map.clearOverlays();
//     var tPoint = new BMapGL.Point(e.point.lng, e.point.lat);
//     marker = new BMapGL.Marker(tPoint);  // 创建标注
//     map.addOverlay(marker);               // 将标注添加到地图中
//     marker.enableDragging();//点可拖拽
//     marker.addEventListener('dragend',function () {
//         if(circle){
//             var point = marker.getPosition();
//             var range = circle.getRadius();
//             addCircle(point,range);
//             search();
//         }
//     });
// });
$('#btn').on('click',function () {
    search();
});
$('#readLocal').on('click',function(){
    DrawLocalData()
})
$('#readLocal1').on('click',function(){


});
function DrawLocalData(){
   
    var localStr = localStorage.getItem('localData');
    localObj = JSON.parse(localStr);
    console.log(localObj);
    map.clearOverlays();

//设置中心点

    var pp = new BMapGL.Point(localObj.center.lng,localObj.center.lat)
    map.centerAndZoom(pp, 16);//设置中心点坐标和地图级别
    console.log(localObj.center.lng,localObj.center.lat);
    var marker = new BMapGL.Marker(pp);
    map.addOverlay(marker);    //添加标注 
    marker.setAnimation(BMAP_ANIMATION_BOUNCE);  //跳动的动画

   //画圆
   addCircle(pp,localObj.range)
   //显示列表及标记点
   var list = localObj.list
    for (var i in list){
        console.log(i);
        draw(list[i],i);
    }
    $table.bootstrapTable('load',list);
    $table.bootstrapTable('hideLoading');
    //显示中心点地址搜索、距离、搜索
    $('#range').val(localObj.range)
    $('#search').val(localObj.search)
	$('#suggestId').val(localObj.placename)
}
function search() {
    $table.bootstrapTable('showLoading');
    map.clearOverlays();
    var r = $('#range').val();
    localObj.range=r;
    var search = $('#search').val();
    localObj.search=search;
    if (!marker && localObj.center){
        var pp = new BMapGL.Point(localObj.center.lng,localObj.center.lat)
        marker = new BMapGL.Marker(pp);
    }
    if(marker == null){
        alert('请先选择所要查询的点');
        return false;
    }
    if(r == '' || isNaN(r)){
        alert('距离范围必须数字');
        return false;
    }
    if(search == ''){
        alert('搜索关键词不能为空');
        return false;
    }
    point = marker.getPosition();       //获取marker的位置
    circle = addCircle(point,r);
    marker.disableDragging();   //禁止拖拽
    if(markerArr) rmMarkers(markerArr);
    pointList = [];
    var options = {
        renderOptions: {map: map, autoViewport: false},
        pageCapacity:5,
        onSearchComplete: function(results){
            console.log('------')
            console.log(results)
            if (results){
                for(var x=0;x<results.getCurrentNumPois();x++){
                    var info = results.getPoi(x);
                    console.log(point,info.point)
                    if (info.point) info['distance'] = map.getDistance(point,info.point).toFixed(2);
                    info['keyword'] = results.keyword;
                    info['uid'] = results.uid;
                    pointList.push(info)
                }

                let nextPage = results.getPageIndex()+1;
                // console.log(nextPage)
                // if(nextPage > results.getNumPages()) {
                //     // map.clearOverlays();
                //
                // }
                console.log('进行下一页')
                local.gotoPage(nextPage);
            }else {
                map.addOverlay(marker);
                marker.setAnimation(BMAP_ANIMATION_BOUNCE);
                //  console.log(pointList.sort(compare('distance')))
                console.log(pointList)
                setList(pointList.sort(compare('distance')))
            }
            console.log(pointList)
        },
        onMarkersSet:function (markers) {
            for(var i in markers){
                map.removeOverlay(markers[i]['marker']);
            }
        }
    };
    let local =  new BMapGL.LocalSearch(map, options);
    var searchArr = search.split(',');
    for (let sk in searchArr) {
        let title = searchArr[sk];
        console.log('搜索：'+title)
        local.searchNearby(title,point,parseInt(r));
    }
}

//添加行政区
$('#regionbtn').on('click',function () {
    let region = document.getElementById('region').value
    getBoundary(region)
})
//清除行政区
$('#regionClear').on('click',function () {
    map.removeOverlay(ply)
})


function getBoundary(region){
    map.removeOverlay(ply)
    var bdary = new BMapGL.Boundary();
    bdary.get(region, function(rs){       //获取行政区域
        // map.clearOverlays();           //清除地图覆盖物
        var count = rs.boundaries.length; //行政区域的点有多少个
        if (count === 0) {
            alert('未能获取当前输入行政区域');
            return ;
        }
        var pointArray = [];
        for (var i = 0; i < count; i++) {
            ply = new BMapGL.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
            map.addOverlay(ply);  //添加覆盖物
            pointArray = pointArray.concat(ply.getPath());
        }
        map.setViewport(pointArray);    //调整视野
    });
}
function addCircle(point,range) {
    if(circle) map.removeOverlay(circle);
    circle = new BMapGL.Circle(point,range,{fillColor:'',strokeWeight: 4 ,fillOpacity: 0, strokeOpacity: 1,strokeColor: 'red'});
    map.addOverlay(circle);
    return circle;
}
function rmMarkers(markers) {
    for(var i in markers){
        map.removeOverlay(markers[i]);
    }
}
function setList(list) {
    console.log(list)
    data = [];
    point = marker.getPosition();  
    var html = '';
	console.log(list)
    for(var i in list){
        var info = list[i];
		if($.inArray(info.title,repeat) != -1) continue;
        var gcj02 = GPS.bd_decrypt(info.point.lat,info.point.lng);
        var wgs84 = GPS.gcj_decrypt_exact(gcj02.lat,gcj02.lon);
        data.push({
            'id':parseInt(i)+1,
            'keyword':info.keyword,
            'title':info.title,
            'address':info.address,
            'phoneNumber':info.phoneNumber,
            'lng':info.point.lng,
            'lat':info.point.lat,
            'gcj02lon':gcj02.lon,
            'gcj02lat':gcj02.lat,
            'wgs84lon':wgs84.lon,
            'wgs84lat':wgs84.lat,
            'distance':info.distance,
            'locative':getDirection(point,info.point)
        })
	
        length = i;
        draw(info,i);
//           markerArr.push(marker);
    }
		console.log(data)
    $table.bootstrapTable('load',data);
    $table.bootstrapTable('hideLoading');
}
var GPS = {
    PI : 3.14159265358979324,
    x_pi : 3.14159265358979324 * 3000.0 / 180.0,
    delta : function (lat, lon) {
        // Krasovsky 1940
        //
        // a = 6378245.0, 1/f = 298.3
        // b = a * (1 - f)
        // ee = (a^2 - b^2) / a^2;
        var a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
        var ee = 0.00669342162296594323; //  ee: 椭球的偏心率。
        var dLat = this.transformLat(lon - 105.0, lat - 35.0);
        var dLon = this.transformLon(lon - 105.0, lat - 35.0);
        var radLat = lat / 180.0 * this.PI;
        var magic = Math.sin(radLat);
        magic = 1 - ee * magic * magic;
        var sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
        dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
        return {'lat': dLat, 'lon': dLon};
    },
//        WGS-84：是国际标准，GPS坐标（Google Earth使用、或者GPS模块）
//        GCJ-02：中国坐标偏移标准，Google Map、高德、腾讯使用
//        BD-09：百度坐标偏移标准，Baidu Map使用

    //WGS-84 to GCJ-02
    gcj_encrypt : function (wgsLat, wgsLon) {
        if (this.outOfChina(wgsLat, wgsLon))
            return {'lat': wgsLat, 'lon': wgsLon};

        var d = this.delta(wgsLat, wgsLon);
        return {'lat' : wgsLat + d.lat,'lon' : wgsLon + d.lon};
    },
    //GCJ-02 to WGS-84
    gcj_decrypt : function (gcjLat, gcjLon) {
        if (this.outOfChina(gcjLat, gcjLon))
            return {'lat': gcjLat, 'lon': gcjLon};

        var d = this.delta(gcjLat, gcjLon);
        return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon};
    },
    //GCJ-02 to WGS-84 exactly
    gcj_decrypt_exact : function (gcjLat, gcjLon) {
        var initDelta = 0.01;
        var threshold = 0.000000001;
        var dLat = initDelta, dLon = initDelta;
        var mLat = gcjLat - dLat, mLon = gcjLon - dLon;
        var pLat = gcjLat + dLat, pLon = gcjLon + dLon;
        var wgsLat, wgsLon, i = 0;
        while (1) {
            wgsLat = (mLat + pLat) / 2;
            wgsLon = (mLon + pLon) / 2;
            var tmp = this.gcj_encrypt(wgsLat, wgsLon)
            dLat = tmp.lat - gcjLat;
            dLon = tmp.lon - gcjLon;
            if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold))
                break;

            if (dLat > 0) pLat = wgsLat; else mLat = wgsLat;
            if (dLon > 0) pLon = wgsLon; else mLon = wgsLon;

            if (++i > 10000) break;
        }
        //console.log(i);
        return {'lat': wgsLat, 'lon': wgsLon};
    },
    //GCJ-02 to BD-09
    bd_encrypt : function (gcjLat, gcjLon) {
        var x = gcjLon, y = gcjLat;
        var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi);
        var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi);
        bdLon = z * Math.cos(theta) + 0.0065;
        bdLat = z * Math.sin(theta) + 0.006;
        return {'lat' : bdLat,'lon' : bdLon};
    },
    //BD-09 to GCJ-02
    bd_decrypt : function (bdLat, bdLon) {
        var x = bdLon - 0.0065, y = bdLat - 0.006;
        var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi);
        var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi);
        var gcjLon = z * Math.cos(theta);
        var gcjLat = z * Math.sin(theta);
        return {'lat' : gcjLat, 'lon' : gcjLon};
    },
    //WGS-84 to Web mercator
    //mercatorLat -> y mercatorLon -> x
    mercator_encrypt : function(wgsLat, wgsLon) {
        var x = wgsLon * 20037508.34 / 180.;
        var y = Math.log(Math.tan((90. + wgsLat) * this.PI / 360.)) / (this.PI / 180.);
        y = y * 20037508.34 / 180.;
        return {'lat' : y, 'lon' : x};
        /*
         if ((Math.abs(wgsLon) > 180 || Math.abs(wgsLat) > 90))
         return null;
         var x = 6378137.0 * wgsLon * 0.017453292519943295;
         var a = wgsLat * 0.017453292519943295;
         var y = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
         return {'lat' : y, 'lon' : x};
         //*/
    },
    // Web mercator to WGS-84
    // mercatorLat -> y mercatorLon -> x
    mercator_decrypt : function(mercatorLat, mercatorLon) {
        var x = mercatorLon / 20037508.34 * 180.;
        var y = mercatorLat / 20037508.34 * 180.;
        y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180.)) - this.PI / 2);
        return {'lat' : y, 'lon' : x};
        /*
         if (Math.abs(mercatorLon) < 180 && Math.abs(mercatorLat) < 90)
         return null;
         if ((Math.abs(mercatorLon) > 20037508.3427892) || (Math.abs(mercatorLat) > 20037508.3427892))
         return null;
         var a = mercatorLon / 6378137.0 * 57.295779513082323;
         var x = a - (Math.floor(((a + 180.0) / 360.0)) * 360.0);
         var y = (1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * mercatorLat) / 6378137.0)))) * 57.295779513082323;
         return {'lat' : y, 'lon' : x};
         //*/
    },
    // two point's distance
    distance : function (latA, lonA, latB, lonB) {
        var earthR = 6371000.;
        var x = Math.cos(latA * this.PI / 180.) * Math.cos(latB * this.PI / 180.) * Math.cos((lonA - lonB) * this.PI / 180);
        var y = Math.sin(latA * this.PI / 180.) * Math.sin(latB * this.PI / 180.);
        var s = x + y;
        if (s > 1) s = 1;
        if (s < -1) s = -1;
        var alpha = Math.acos(s);
        var distance = alpha * earthR;
        return distance;
    },
    outOfChina : function (lat, lon) {
        if (lon < 72.004 || lon > 137.8347)
            return true;
        if (lat < 0.8293 || lat > 55.8271)
            return true;
        return false;
    },
    transformLat : function (x, y) {
        var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
        return ret;
    },
    transformLon : function (x, y) {
        var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
        return ret;
    }
};
function getAngle(px,py,mx,my){//获得人物中心和鼠标坐标连线，与y轴正半轴之间的夹角
    var x = Math.abs(px-mx);
    var y = Math.abs(py-my);
    var z = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
    var cos = y/z;
    var radina = Math.acos(cos);//用反三角函数求弧度
    var angle = Math.floor(180/(Math.PI/radina));//将弧度转换成角度

    if(mx>px&&my>py){//鼠标在第四象限
        angle = 180 - angle;
    }
    if(mx==px&&my>py){//鼠标在y轴负方向上
        angle = 180;
    }
    if(mx>px&&my==py){//鼠标在x轴正方向上
        angle = 90;
    }
    if(mx<px&&my>py){//鼠标在第三象限
        angle = 180+angle;
    }
    if(mx<px&&my==py){//鼠标在x轴负方向
        angle = 270;
    }
    if(mx<px&&my<py){//鼠标在第二象限
        angle = 360 - angle;
    }
    return angle;
}
function getDirection(pointA, pointB) {
    var angle = getAngle(pointA.lng,pointA.lat,pointB.lng,pointB.lat);
    var direction = '';

    switch (true){
        case (angle>=337.5 || angle<=22.5):
            direction = '南';
            break;
        case (22.5<=angle && angle<=67.5):
            direction = '东南';
            break;
        case (67.5<=angle && angle<=112.5):
            direction = '东';
            break;
        case (112.5<=angle && angle<=157.5):
            direction = '东北';
            break;
        case (157.5<=angle && angle<=202.5):
            direction = '北';
            break;
        case (202.5<=angle && angle<=247.5):
            direction = '西北';
            break;
        case (247.5<=angle && angle<=292.5):
            direction = '西';
            break;
        case (292.5<=angle && angle<=337.5):
            direction = '西南';
            break;
        default:
            direction = '原地';
    }
    return direction;
}
//排序
function compare(property){
    return function(a,b){
        var value1 = a[property];
        var value2 = b[property];
        return value1 - value2;
    }
}
//去除数组中的空值
function trimSpace(array){
    for(var i = 0 ;i<array.length;i++) {
        if(array[i] == "" || typeof(array[i]) == "undefined") {
            array.splice(i,1);
            i= i-1;
        }
    }
    return array;
}
function draw(info,i) {
    if(!info["point"]){
        var point = new BMapGL.Point(info.lng,info.lat)
        info.point = point
    }

    var marker = new BMapGL.Marker(info.point);
    map.addOverlay(marker);
    let x = (i+1) >= 10 ?-5:25;
    console.log('x:',x)
    var label = new BMapGL.Label(parseInt(i)+1,{offset:new BMapGL.Size(x,-23)});
    label.setStyle({
        color : "white",
        fontSize : "12px",
        height : "15px",
        lineHeight : "15px",
        fontFamily:"微软雅黑",
        backgroundColor:'none',
        border:'none',
        textAlign:'center'
    });
    marker.setLabel(label);
}
$('#addflag').click(function () {
    if(!marker) {alert('没有中心点！'); return;}
    // let info = [];
    // info['point'] = new BMapGL.Point($('.j').val(),$('.w').val());
    let F_point = [];
    F_point['lng'] = $('.j').val()
    F_point['lat'] = $('.w').val()

	console.log(marker.point)

    // length++;
    // let gcj02 = GPS.bd_decrypt(info.point.lat,info.point.lng);
    // let wgs84 = GPS.gcj_decrypt_exact(gcj02.lat,gcj02.lon);
    // data.push({
    //     0:undefined,
    //     'id':parseInt(length)+1,
    //     'keyword':$('.ty').val(),
    //     'title':$('.n').val(),
    //     'address':$('.a').val(),
    //     'phoneNumber':$('.t').val(),
    //     'lng':$('.j').val(),
    //     'lat':$('.w').val(),
    //     'gcj02lon':gcj02.lon,
    //     'gcj02lat':gcj02.lat,
    //     'wgs84lon':wgs84.lon,
    //     'wgs84lat':wgs84.lat,
    //     'distance':map.getDistance(marker.getPosition(),info.point).toFixed(2),
    //     'locative':getDirection(marker.getPosition(),info.point)
    // })
    // draw(info,length)
    // $table.bootstrapTable('load',data);
	let point = new BMapGL.Point(marker.point.lng,marker.point.lat)
	let distance = map.getDistance(point,F_point).toFixed(2);
	console.log(point)
	console.log(distance)
    pointList.push({
        'keyword':$('.ty').val(),
        'title':$('.n').val(),
        'address':$('.a').val(),
        'phoneNumber':$('.t').val(),
        'point':F_point,
        'distance':distance
    })
    setList(pointList.sort(compare('distance')))
})

$table.bootstrapTable({
    data: data,
    clickToSelect: true,
    showExport: true,
    columns: [{
        checkbox:true
    },{
        field: 'id',
        title: 'ID',
        width: 30,
        align: 'center',    sortable: true
    }, {
        field: 'keyword',
        title: '类型',
        align: 'center',  sortable: true
    }, {
        field: 'title',
        title: '名称',    sortable: true
    },{
        field: 'address',
        title: '地址',    sortable: true
    },{
        field:'phoneNumber',
        title: '电话',    sortable: true
    }, {
        field: 'lng',
        title:'经度(百度)',    sortable: true
    }, {
        field: 'lat',
        title:'维度(百度)',    sortable: true
    }, {
        field: 'gcj02lon',
        title:'经度(中国标准)',    sortable: true
    }, {
        field: 'gcj02lat',
        title:'维度(中国标准)',    sortable: true
    }, {
        field: 'wgs84lon',
        title:'经度(国际标准)',    sortable: true
    }, {
        field: 'wgs84lat',
        title:'维度(国际标准) ',    sortable: true
    }, {
        field: 'distance',
        title:'距离（米）',
        sortable: true
    }, {
        field: 'locative',
        title:'相对方位',
        sortable: true
    }]
});
$table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
    $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
    $button.prop('disabled', !$table.bootstrapTable('getSelections').length);
});
$remove.click(function () {
    var ids = $.map($table.bootstrapTable('getSelections'), function (row) {
        delete pointList[row.id-1]
        return row.id;
    });
    $table.bootstrapTable('remove', {
        field: 'id',
        values: ids
    });
    $remove.prop('disabled', true);
    map.clearOverlays();
    map.addOverlay(marker);
    marker.setAnimation(BMAP_ANIMATION_BOUNCE);
    var range = circle.getRadius();
    addCircle(point,range);
    let list = trimSpace(pointList)
	repeat = [];
    setList(list);
})
$('#unique').on('click',()=>{
    let list = data,
        arr = {};
    for (let listKey in list) {
        let item = list[listKey];
        if (item.title.indexOf('-') === -1){
            let tem = item.split('-')
            if (!arr[tem[0]]) arr[tem[0]] = [];
            arr[tem[0]].push(item)
        }else {
            if (!arr[item.title]) arr[item.title] = [];
            arr[item.title].unshift(item)
        }
    }
})







